#ifndef _PD_H__
#define _PD_H__

#define BMC_HALF_BIT  133
#define BMC_FULL_BIT  267  //3.33us*80MHz=266.66

#define BMC_HALF_BIT_MIN  107  //133*0.8
#define BMC_HALF_BIT_MAX  160  //133*1.2
#define BMC_FULL_BIT_MIN  214  //267*0.8
#define BMC_FULL_BIT_MAX  320  //267*1.2

#define BMC_5B_HEX0     0x1E
#define BMC_5B_HEX1     0x09
#define BMC_5B_HEX2     0x14
#define BMC_5B_HEX3     0x15
#define BMC_5B_HEX4     0x0A
#define BMC_5B_HEX5     0x0B
#define BMC_5B_HEX6     0x0E
#define BMC_5B_HEX7     0x0F
#define BMC_5B_HEX8     0x12
#define BMC_5B_HEX9     0x13
#define BMC_5B_HEXA     0x16
#define BMC_5B_HEXB     0x17
#define BMC_5B_HEXC     0x1A
#define BMC_5B_HEXD     0x1B
#define BMC_5B_HEXE     0x1C
#define BMC_5B_HEXF     0x1D
#define BMC_5B_SYNC1    0x18
#define BMC_5B_SYNC2    0x11
#define BMC_5B_SYNC3    0x06
#define BMC_5B_RST1     0x07
#define BMC_5B_RST2     0x19
#define BMC_5B_EOP      0x0D

//Message Header
#define PD_MSG_HEADER_EX        (1<<15)
//14:12 -- Number of Data Objects
//11:9 -- MessageID
#define PD_MSG_HEADER_SOURCE    (1<<8)
#define PD_MSG_HEADER_SINK      (0<<8)
//7:6 -- Specification Revision
#define PD_MSG_HEADER_DFP       (1<<5)
#define PD_MSG_HEADER_UFP       (0<<5)
//4:0 -- Message Type

//Control Message
#define PD_MSG_CTRL_GoodCRC     0x01

//Data Message
#define PD_MSG_DATA_SourceCapabilities  0x01
//Extended Message

//SOP SOP' SOP''
struct Pd_SOP{
    u8  Order[4];
}Pd_Recv_SOP,Pd_Trans_SOP;
//Dont support Extened Message
struct Pd_Message{
    u16 Header;
    u32 Data[7];
    u32 Crc;
}Pd_Recv_Message,Pd_Trans_Message;

u16 u16PdCapCounter;
u16 u16ArrayPdCapData[1024];
u8 u8TransNumberData;
u8 u8ArrayTransBuf[4+7*8+8];

void X_PdInit();
void X_PdRecvBufInit();
void X_PdTransBufInit();

#endif
